<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
</head>

<body>
    <div id="div1">

    </div>
</body>
<script type="text/javascript">
    //		1:创建XMLHttpRequest对象     考虑兼容性问题
    var xhr = null;
    if (window.XMLHttpRequest) {
        //主流浏览器
        xhr = new XMLHttpRequest();
    } else {
        //ie6  ie5
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }

    console.log(xhr)
    console.log(xhr.readyState + "000")

    //		2:建立连接
    xhr.open("get", "http://127.0.0.1:5500/day06/data/1.txt", true) //http://www.baidu.com/data/1.txt   url
    console.log(xhr.readyState + "111")
        //		3:发送请求
    xhr.send(null);
    console.log(xhr.readyState + "222")

    //		4:获取响应的数据
    xhr.onreadystatechange = function() { //readystate  0 1 2 3 4
        console.log(xhr.readyState + "333")
        if (xhr.readyState == 4 && xhr.status == 200) { //
            console.log(xhr.readyState + "444")
            var data = xhr.responseText;
            console.log(data)
            show(data)
        }

    }


    function show(data) {
        document.getElementById("div1").innerHTML = data;
    }
</script>

</html>